package com.android.yinghebike.ui.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.android.baselibrary.interface_.OkHttpCallBack;
import com.android.baselibrary.responce.BaseResponce;
import com.android.baselibrary.tool.CommToast;
import com.android.baselibrary.view.Comm_EditView;
import com.android.baselibrary.view.Comm_HeadView;
import com.android.baselibrary.view.MultiStateView;
import com.android.yinghebike.R;
import com.android.yinghebike.bean.UserInfo;
import com.android.yinghebike.constants.Constants;
import com.android.yinghebike.manager.API_Manager;
import com.android.yinghebike.manager.UserManager;

import butterknife.BindView;
import butterknife.OnClick;

public class AccountActivity extends BaseActivity {

    @BindView(R.id.multiplestatusView)
    MultiStateView multiplestatusView;
    @BindView(R.id.comm_title)
    Comm_HeadView comm_title;
    @BindView(R.id.tv_account)
    TextView tv_account;
    @BindView(R.id.et_old_pwd)
    Comm_EditView et_old_pwd;
    @BindView(R.id.et_new_pwd1)
    Comm_EditView et_new_pwd1;
    @BindView(R.id.et_new_pwd2)
    Comm_EditView et_new_pwd2;

    UserInfo userInfo;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_account;
    }

    @Override
    protected void initView() {
        comm_title.setTitle(getString(R.string.mine_account));
    }

    @Override
    protected void initData() {
        userInfo = UserManager.getUserInfo(mContext);
        tv_account.setText(userInfo.account);
    }


    @OnClick({R.id.csb_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.csb_submit:
                editPwd();
                break;
        }
    }

    private void editPwd() {
        String old_pwd = et_old_pwd.getText();
        String new_pwd1 = et_new_pwd1.getText();
        String new_pwd2 = et_new_pwd2.getText();
        if (TextUtils.isEmpty(old_pwd)) {
            CommToast.showToast(mContext, getString(R.string.account_hint_oldpwd));
            return;
        }
        if (TextUtils.isEmpty(new_pwd1)) {
            CommToast.showToast(mContext, getString(R.string.account_hint_newpwd));
            return;
        }
        if (TextUtils.isEmpty(new_pwd2)) {
            CommToast.showToast(mContext, getString(R.string.account_hint_newpwd1));
            return;
        }
        if (!new_pwd1.equals(new_pwd2)) {
            CommToast.showToast(mContext, getString(R.string.account_tips_inconsistent));
            return;
        }
        if (new_pwd1.equals(old_pwd)) {
            CommToast.showToast(mContext, getString(R.string.account_tips_repeat));
            return;
        }
        if(!old_pwd.equals(userInfo.pwd))
        {
            CommToast.showToast(mContext, getString(R.string.account_tips_oldpwd_error));
            return;
        }
        userInfo.pwd = new_pwd1 ;
        userInfo.save();
        CommToast.showToast(mContext, getString(R.string.comm_tips_success));
        finish();
    }
}
